﻿@*
//------------------------------------------------------------------------------
//  此代码版权声明为全文件覆盖，如有原作者特别声明，会在下方手动补充
//  此代码版权（除特别声明外的代码）归作者本人Diego所有
//  源代码使用协议遵循本仓库的开源协议及附加协议
//  Gitee源代码仓库：https://gitee.com/diego2098/ThingsGateway
//  Github源代码仓库：https://github.com/kimdiego2098/ThingsGateway
//  使用文档：https://diego2098.gitee.io/thingsgateway-docs/
//  QQ群：605534569
//------------------------------------------------------------------------------
*@

@namespace ThingsGateway.Foundation.Demo

@using BlazorComponent;
@using Microsoft.AspNetCore.Components.Web;
@using Opc.Ua;
@using System.Reflection;
@using ThingsGateway.Foundation.Adapter.OPCUA;
@using ThingsGateway.Foundation.Core;
@using Masa.Blazor

<MCard Class="ma-0">
    <MCardTitle Class="indigo white--text text-h6">
        @PLC?.OPCNode?.OPCUrl
    </MCardTitle>
    <MRow Class="pa-4"
          Justify="JustifyTypes.SpaceBetween">
        <MCol Cols="12" Md="6">
            <MTreeview @bind-Value=Selected @bind-Active=Actived SelectionType="SelectionType.Leaf"
                       Items=Nodes TItem=OPCUATagModel
                       Color="warning" Selectable Activatable OpenOnClick
                       LoadChildren=PopulateBranchAsync
                       TKey=ReferenceDescription ItemKey="r=>r.Tag"
                       Style="height:500px;overflow-y:auto;"
                       ItemText="r=>r.Name"
                       ItemChildren="r=>r.Nodes">

            </MTreeview>

        </MCol>
        <MCol Cols="12" Md="6">
            <MCardText Style="height:500px;overflow-y:auto;">
                @if (Actived?.Count == 0 || Actived?.FirstOrDefault()?.NodeId==null)
                {
                    <div key="title"
                         class="text-h6 font-weight-light grey--text pa-4 text-center">
                        选择左侧节点
                    </div>
                }
                else
                {
                    <ScrollXTransition>
                        <MSheet Outlined Class="ma-0 pa-1">
                            <MRow Align="AlignTypes.Center">
                                <MCol>
                                    <MListItem>
                                        <ItemContent>
                                            <MListItemContent>
                                                <MListItemTitle>NodeId </MListItemTitle>
                                            </MListItemContent>
                                        </ItemContent>
                                    </MListItem>
                                </MCol>
                                <MDivider Vertical Center />
                                <MCol>
                                     <MLabel Class=@($"ma-1")> @Actived.FirstOrDefault().NodeId  </MLabel>
                                </MCol>

                            </MRow>
                        </MSheet>
                        @foreach (var item in nodeAttributes)
                        {
                            <MSheet Outlined Class="ma-0 pa-1">
                                <MRow Align="AlignTypes.Center">
                                    <MCol>
                                        <MListItem>
                                            <ItemContent>
                                                <MListItemContent>
                                                    <MListItemTitle>@item.Name </MListItemTitle>
                                                </MListItemContent>
                                            </ItemContent>
                                        </MListItem>
                                    </MCol>
                                    <MDivider Vertical Center />
                                    <MCol>
                                        <MLabel Class=@($"{(StatusCode.IsBad(item.StatusCode)?"red--text":"green--text")} ma-1")> @item.Value  </MLabel>
                                    </MCol>

                                </MRow>
                            </MSheet>
                        }

                    </ScrollXTransition>

                }
            </MCardText>
        </MCol>

        <MDivider Vertical></MDivider>

    </MRow>

</MCard>
<MOverlay Absolute Value="overlay" Opacity="0.8">
    <span class="green--text text--darken-2">
        @("正在获取OPCUA节点...")
    </span>
    <MProgressCircular Indeterminate Width=6
                       Size="30"></MProgressCircular>
</MOverlay>
